
<template>
	<div class="index">

		<div class="center">
			<left></left>
			<div class="right">
          <top></top>
          <!-- <div class="hei10"></div>
          <div class="where" style="background: #fff; padding: 10px 30px; font-size: 14px; color: #595959;">当前位置：分销后台><router-link to="/productionBasismanag" style="color: #409eff;">产品渠道管理</router-link></div>
          --><div class="hei10"></div>
				<div class="o_ul">
					<router-link class="o_li acts bgw"  to="/productionBasismanag" >产品渠道中心</router-link>
					<router-link class="o_li" v-if="checkquanxian('P010102').length > 0" to="/productionBasismanag/productionBasismanagSoldout">已下架的产品</router-link>
					<router-link class="o_li" v-if="checkquanxian('P010103').length > 0" to="/productionBasismanag/productionBasismanagDj">自动生产对接</router-link>
				</div>
				<div class="bsm">
					<el-form ref="form" @submit.native.prevent :model="form" label-width="80px">
						<div class="cpflex">
							<el-form-item label="产品名称" class="bgh" style="margin-right: 20px;">
								<el-input v-model="title" placeholder="请输入产品名称"></el-input>
							</el-form-item>
							<el-form-item label="产品编码" class="bgh" style="margin-right: 20px;">
								<el-input v-model="sku" placeholder="请输入产品编码"></el-input>
							</el-form-item>
							<el-button type="danger" round @click="search" style="margin-left:20px;">搜索
							</el-button>

							<el-button type="danger" plain round @click="daochu" style="margin-left:20px;">导出
							</el-button>
						</div>


					</el-form>
					<div class="row2">
						<el-button type="danger" round v-if="P0102" @click="goto">新增产品（渠道）</el-button>
            <el-button type="danger" round @click="chuangjian2">通过复制创建产品</el-button>
						<el-button type="danger" round @click="numberManager">号码管理</el-button>
					</div>
				</div>

				<div class="con">
          <el-table :data="list" style="text-align: center;" align="center" border :loading="loading" :header-cell-style="{
                        background:'#F4F4F4',
                        color:'#7D8087'}">
            <el-table-column label="产品名称" align="center" width="300">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="产品编码" align="center" width="300">
              <template slot-scope="scope">
                <span>{{ scope.row.sku }}</span>
              </template>
            </el-table-column>
            <el-table-column label="运营商" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.operator }}</span>
              </template>
            </el-table-column>
            <el-table-column label="生产方式" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.is_auto_produce == 0"> 手动生产</span>
                <span v-if="scope.row.is_auto_produce == 1"> 自动生产</span>
                <i v-if="P0102" class="el-icon-edit lanse" style="margin-left: 10px;" @click="changeis_auto_produce(scope.row)"></i>
<!--                <span v-if="scope.row.is_auto_produce == 2"> 自动生产多</span>
                <i v-if="P0102" class="el-icon-edit lanse" style="margin-left: 10px;" @click="changeis_auto_produce(scope.row)"></i> -->
              </template>
            </el-table-column>
            <el-table-column label="多接口生产配置" align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="goid('/productionBasismanag/zidongshengchanguanli',scope.row.id)">配置</el-button>
              </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.created_at }}</span>
              </template>
            </el-table-column>

            <el-table-column label="库存数" align="center">
              <template slot-scope="scope">
                {{scope.row.stock}}<i class="el-icon-edit lanse" style="margin-left: 10px;"
                		@click="changestock(scope.row.id,scope.row.stock)"></i>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="400">
              <template slot-scope="scope">

                <el-button type="text" v-if="P0102" @click="detail(scope.row.id)">查看详情</el-button>
                <el-button type="text" v-if="P0102" @click="go(scope.row.id)">编辑</el-button>
                <el-button type="text" v-if="P0102" @click="see(scope.row.id,scope.row.name)">查看关联商品</el-button>
                <!-- <el-button type="text" size="mini" @click="godaliang(item.id)">达量提醒</el-button> -->
                <el-button type="text" v-if="P0102" @click="gomoneyset(scope.row.id)">佣金规则设置</el-button>
                <el-button type="text" v-if="P0102" @click="soldout(scope.row.id)">下架</el-button>


              </template>
            </el-table-column>
          </el-table>
<el-pagination background layout="total, prev, pager, next" style="text-align: right; margin: 20px;" prev-text="上一页" next-text="下一页" :current-page="page" @current-change="fanye"
					:page-size="pagesize" :total="total"></el-pagination>
				</div>

			</div>
			<el-dialog title="添加反向自动处理规则" center :visible.sync="is_auto_producelog" width="480px">
				<div style="margin-bottom: 10px;">
          <el-select v-model="all2.is_auto_produce" style="width: 100%;" @change="is_auto" filterable placeholder="修改生产方式">
          	<el-option label="手动生产" :value="0"></el-option>
            <el-option label="自动生产" :value="1"></el-option>
          </el-select>
				</div>
				<!-- <div>
          <div v-if="all2.is_auto_produce == 1">
            <div style="color: rgb(80, 80, 80); margin-bottom: 10px;">
              已配置的自动提单接口
            </div>
            <div class="kflexc" style="margin-bottom: 10px;">
              <div>
                <el-select v-model="inputadd.channel_id" @change="getpeizhi" filterable placeholder="选择渠道">
                  <el-option :label="item.user_defined_name" :value="item.channel_id" v-for="item in jiekouqudaolist" :key="item.id"></el-option>
                </el-select>
              </div>
              <div style="color: rgb(0, 126, 255);" @click="peizhikai()">配置信息</div>
              <div style="color: rgb(0, 126, 255);" @click="peizhikai2()">配置信息2</div>
            </div>
          </div>

          <div v-if="all2.is_auto_produce == 2">
              <div v-for="(item,index) in arr" :key="item">
                <div class="kflexc" v-if="index != 0">
                  <div class="kflexc" style="margin-bottom: 10px;">
                    <div style="color: rgb(0, 0, 0);">已配置的接口{{index}}</div><div style="color: rgb(0, 126, 255); margin-left: 20px;">删除</div>
                  </div>
                  <div class="kflexc" style="margin-bottom: 10px;">
                    <div style="color: rgb(136, 137, 137);">当用户收件地址为：</div>
                    <el-select v-model="item.first_province" style="width: 120px;" clearable placeholder="请选择省份:">
                      <el-option label="北京市" value="北京市"></el-option>
                      <el-option label="天津市" value="天津市"></el-option>
                      <el-option label="河北省" value="河北省"></el-option>
                      <el-option label="山西省" value="山西省"></el-option>
                      <el-option label="内蒙古自治区" value="内蒙古自治区"></el-option>
                      <el-option label="吉林省" value="吉林省"></el-option>
                      <el-option label="黑龙江省" value="黑龙江省"></el-option>
                      <el-option label="上海市" value="上海市"></el-option>
                      <el-option label="江苏省" value="江苏省"></el-option>
                      <el-option label="浙江省" value="浙江省"></el-option>
                      <el-option label="安徽省" value="安徽省"></el-option>
                      <el-option label="辽宁省" value="辽宁省"></el-option>
                      <el-option label="福建省" value="福建省"></el-option>
                      <el-option label="江西省" value="江西省"></el-option>
                      <el-option label="山东省" value="山东省"></el-option>
                      <el-option label="河南省" value="河南省"></el-option>
                      <el-option label="湖北省" value="湖北省"></el-option>
                      <el-option label="湖南省" value="湖南省"></el-option>
                      <el-option label="广东省" value="广东省"></el-option>
                      <el-option label="广西壮族自治区" value="广西壮族自治区"></el-option>
                      <el-option label="海南省" value="海南省"></el-option>
                      <el-option label="重庆市" value="重庆市"></el-option>
                      <el-option label="四川省" value="四川省"></el-option>
                      <el-option label="贵州省" value="贵州省"></el-option>
                      <el-option label="云南省" value="云南省"></el-option>
                      <el-option label="西藏自治区" value="西藏自治区"></el-option>
                      <el-option label="陕西省" value="陕西省"></el-option>
                      <el-option label="甘肃省" value="甘肃省"></el-option>
                      <el-option label="青海省" value="青海省"></el-option>
                      <el-option label="宁夏回族自治区" value="宁夏回族自治区"></el-option>
                      <el-option label="新疆维吾尔自治区" value="新疆维吾尔自治区"></el-option>
                      <el-option label="台湾省" value="台湾省"></el-option>
                      <el-option label="香港特别行政区" value="香港特别行政区"></el-option>
                      <el-option label="澳门特别行政区" value="澳门特别行政区"></el-option>
                    </el-select>
                    <div style="color: rgb(136, 137, 137);">则自动提单至下方接口</div>
                  </div>
                  <div class="kflexc" style="margin-bottom: 10px;">
                    <div>
                      <el-select v-model="item.channel_id" filterable placeholder="选择渠道">
                        <el-option :label="item2.user_defined_name" :value="item2.channel_id" v-for="item2 in jiekouqudaolist" :key="item.id"></el-option>
                      </el-select>
                    </div>
                    <div style="color: rgb(0, 126, 255);" @click="peizhikai(index+1,item.channel_id)">配置信息</div>
                  </div>
                </div>
              </div>
              <div>
                <el-button type="primary" round @click="tianjia">+添加新接口</el-button>
              </div>
              <div style="margin-bottom: 10px;">
                <div style=" font-weight: bold;">主提单接口</div>
              </div>
              <div style="margin-bottom: 10px;">
                以上接口都不满足条件时自动提交至该接口
              </div>
              <div class="kflexc" style="margin-bottom: 10px;">
                <div>
                  <el-select v-model="inputadd.channel_id" @change="getpeizhi" filterable placeholder="选择渠道">
                    <el-option :label="item.user_defined_name" :value="item.channel_id" v-for="item in jiekouqudaolist" :key="item.id"></el-option>
                  </el-select>
                </div>
                <div style="color: rgb(0, 126, 255);" @click="peizhikai(0,inputadd.channel_id)">配置信息</div>
              </div>
            </div>
          </div> -->


				<span slot="footer" class="dialog-footer">
          <!-- <el-button @click="addpro" type="danger" round v-if="all2.is_auto_produce == 1 || all2.is_auto_produce == 2 ">确定</el-button> -->
					<!-- <el-button  type="danger" round @click="changeis_auto_producego" v-if="all2.is_auto_produce == 0">确定</el-button> -->

          <el-button  type="danger" round @click="changeis_auto_producego">确定</el-button>
				</span>
			</el-dialog>

			<el-dialog title="码上购产品ID配置" center :visible.sync="mashanglog" width="600px" :close-on-click-modal="false">
				<div v-loading="mashangloading">
					<el-form ref="form" @submit.native.prevent :model="form" label-width="120px">


						<el-form-item label="选择渠道">
							<el-select v-model="mashangqudaoid" filterable placeholder="请选择渠道" @change="mashangchange">
								<el-option v-for="item in mashangqudao" :key="item" :label="item" :value="item">
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="产品id">
							<el-input v-model="mashang.upstream_product_name" placeholder></el-input>
						</el-form-item>
						<div v-for="item in mashang.params" :key="item.key">
							<el-form-item :label="item.description">
								<el-input v-model="item.value" placeholder></el-input>
							</el-form-item>
						</div>
					</el-form>
				</div>

				<span slot="footer" class="dialog-footer">
					<el-button type="danger" round @click="mashanggo">确定</el-button>
				</span>
			</el-dialog>

      <el-dialog title="通过复制创建产品" center :visible.sync="chuangjianlog" width="600px" :close-on-click-modal="false">
      	<div style="display: flex; align-items: center; margin-bottom: 20px;">
          <div style="width: 120px; text-align: right; margin-right: 20px;">选择产品</div>
          <el-select v-model="xin.id" style="width: 220px;" filterable placeholder="请选择产品" >
          	<el-option v-for="item in list2" :key="item.id" :label="item.name" :value="item.id">
          	</el-option>
          </el-select>
        </div>
        <div style="display: flex; align-items: center; margin-bottom: 20px;">
          <div style="width: 120px; text-align: right; margin-right: 20px;">输入新的产品名称</div>
          <el-input v-model="xin.name" style="width: 220px;" placeholder="输入新的产品名称"></el-input>
        </div>
        <div style="display: flex; align-items: center; margin-bottom: 20px;">
          <div style="width: 120px; text-align: right; margin-right: 20px;">输入新的产品编码</div>
          <el-input v-model="xin.sku" style="width: 220px;" placeholder="输入新的产品编码"></el-input>
        </div>
		<div style="padding-left: 140px;">
			<el-checkbox v-model="xin.copy_channel" :true-label="1" :false-label="0">同时复制该产品的接口渠道配置信息</el-checkbox>
		</div>


        <span slot="footer" class="dialog-footer">
        	<el-button  type="danger" round @click="chuangjian2go">确定</el-button>
        </span>
      </el-dialog>

			<el-dialog title="修改库存" center :visible.sync="fixstocklog" width="600px" :close-on-click-modal="false">
				<div class="kucun">
					<el-input v-model="stock" placeholder="输入数量"></el-input>
					<el-button type="danger" round @click="stockgo" style="margin-left:10px;">确定</el-button>
				</div>
				<div class="see" @click="kucunkanbukan = true">查看详情</div>
				<div class="kucun" style="margin-top:30px;" v-if="kucunkanbukan">
					<div class="list">
						<div class="th bor1">时间</div>
						<div class="th bor1">操作人</div>
						<div class="th bor1">库存变化</div>
					</div>

					<div class="list" v-for="item in stocklist" :key="item.id">
						<div class="td bor1">{{item.created_at}}</div>
						<div class="td bor1">{{item.name}}</div>
						<div class="td bor1" v-if="item.alter_amount > 0">+{{item.alter_amount}}</div>
						<div class="td bor1" v-if="item.alter_amount <= 0">{{item.alter_amount}}</div>
					</div>
				</div>
			</el-dialog>

      <el-dialog center  title="添加/编辑"  :visible.sync="addproshow" width="600px" @beforeClose="baocunpeizhi">
      	<el-form  label-width="120px">
            <el-form-item label="本地产品编码">
              <el-input style="width:250px" v-model="all2.sku" disabled placeholder="请输入本地产品编码" size="small" ></el-input>
      			  <el-button @click="checkbm(all2.sku)" type="danger" round>检测</el-button>
      			  <div v-if="ischeck">
                  <div v-if='nopz'>当前产品未配置</div>
      			  		<div v-else>已配置,上游编码为{{upbm}}</div>
      			  </div>
            </el-form-item>
            <el-form-item label="对应上游编码">
                <el-input v-model="inputadd.upstream_account" placeholder="请输入对应上游编码" size="small" ></el-input>
            </el-form-item>
      		<el-form-item v-for="(item,index) in inputlistall" :key="index" :label="item.name">
      			<el-input v-if='item.type=="text"' @input="inputChange"  v-model="inputadd.data[item.key]" size="small" :type="item.type" ></el-input>
      			<el-radio-group v-if='item.type=="radio"' v-model="inputadd.data[item.key]">
      				<el-radio @change="inputChange" v-for="(item2,index2) in item.data"
      				:key="index2"
      				:label="item2.value" >{{item2.name}}</el-radio>
      			</el-radio-group>
      		</el-form-item>
        </el-form>
      	<div class="kflexcc" style="width: 100%;">
      		<el-button @click="baocunpeizhi" type="danger" round>保存配置</el-button>
      	</div>
      </el-dialog>
		</div>

		<!-- <foot></foot> -->
	</div>
</template>

<script>
	import axios from 'axios'
	import top from '@/components/top.vue'
	import left from '@/components/left.vue'
	import foot from '@/components/foot.vue'


	export default {
		components: {
			"left": left,
			"top": top,
			"foot": foot
		},
		name: 'productionBasismanag',
		data() {
			return {
        xin:{
          id:"",
          name:"",
          sku:"",
		  copy_channel:1
        },
        chuangjianlog:false,
				mashangloading: false,
				mashangqudaoid: "",
				mashangqudao: "",
				mashanglog: false,
				mashang: {
					// upstream_product_name:"",
					// upstream_account:"",
					// params:{
					// 	description:"",
					// 	value:"",
					// 	key:""
					// }
				},
				id: "",

				form: {},
				list: "",
				title: "",
				sku: "",
				loading: true,

				chooseid: "",
				is_auto_producelog: false,
				is_auto_produce: '0',

				total: 0,
				page: 1,
				pagesize: 20,

				fixstocklog: false,
				stock: "",
				stocklist: "",
				kucunkanbukan: false,
				P0102:false,
        shopid:"",
        list2:[],
        all2:{},
        jiekouqudaolist:"",

        addproshow:false,
        //添加数据
        inputadd:{
          channel_id:"",
          data:{},
          first_city:"",
          first_order: 0,
          first_province:"",
          id:"",
          product_id:"",
          upstream_account:"",
          upstream_product_name:""
        },
        //动态input
        inputlist:[],
        //动态radio
        radiolist:[],
        //所有动态数据
        inputlistall:[],
        //y_name
        y_name:'',
        //是否点击检查
        ischeck:false,
        //没有配置
        nopz:true,
        //上游编码
        upbm:'',
        upimglink:'',
        get_product_id:'',
        showgetzy:false,
        nowzyid:'',
        shopid: "",
        arr:[
          {
              c_name:"",
              channel_id:"",
              created_at:"",
              data:"",
              first_city:"",
              first_order:"",
              first_province:"",
              id:"",
              product_id:"",
              shop_id:"",
              status:"",
              updated_at:"",
              upstream_account:"",
              upstream_product_name:""
          }
        ]
			}
		},
    beforeDestroy() {
      document.onkeydown = null
    },

		created() {
      //店铺权限问题
      this.shopid = JSON.parse(localStorage.getItem('SHOP')).shop_id;
			//按回车键搜索
			var that = this
			document.onkeydown = function(e) {
				var ev = document.all ? window.event : e;
				if (ev.keyCode == 13) {
					that.search()
				}
			}

			//权限问题
			var user = JSON.parse(localStorage.getItem('USER'));
			this.user_func = user.functions
			for (var i in this.user_func) {
				if (this.user_func[i] != null) {
					var func_number = this.user_func[i].code
				}

				if (func_number.indexOf("P0102") >= 0) {
					this.P0102 = true
				}
			}

			this.getpro()
			this.mashanggetqudao()
      this.getjiekouqudao()

		},

		methods: {
      tianjia:function(){
        this.arr.push(
          {
              c_name:"",
              channel_id:"",
              created_at:"",
              data:"",
              first_city:"",
              first_order:"",
              first_province:"",
              id:"",
              product_id:"",
              shop_id:"",
              status:"",
              updated_at:"",
              upstream_account:"",
              upstream_product_name:""
          }
        )
      },
      inputChange(){
      	this.$forceUpdate();  //强制刷新
      },
      //检查编码
      checkbm(product_sku){
      	axios.get('/api/plan-market/upstream/check/product',{
      		params:{
      			product_sku:product_sku
      		}
      	})
      	.then((response) => {
      		this.ischeck=true
      		console.log(response)
      		if(response.data.data==null){
      			this.nopz=true
      		}else{
      			this.nopz=false
      			this.upbm=response.data.data.upstream_product_name
      		}
      	})
      },
      baocunpeizhi:function(){
        this.arr[0] = JSON.parse(JSON.stringify(this.inputadd))
        this.arr[0].data = JSON.stringify(this.arr[0].data)
        // if(this.all2.index == 'one'){
        //   this.arr[0] = this.inputadd
        // }else{
        //   // this.arr[this.all2.index].channel_id = this.inputadd.channel_id
        //   // this.arr[this.all2.index].data = JSON.stringify(this.inputadd)
        //   // this.arr[this.all2.index].first_order = this.all2.index
        //   // this.arr[this.all2.index].product_id = this.all2.chooseid
        //   // this.arr[this.all2.index].upstream_account = this.inputadd.upstream_sku
        //   // this.arr[this.all2.index].upstream_product_name = this.y_name
        // }

        // console.log(this.arr)
      },
      //确定提交
      addpro(){
      	axios.post('/api/plan-market/make/up/products',{data:this.arr})
      	.then((response) => {
      		if(response.data.msg.code==0){
      			this.$message({
      				message: '操作成功',
      				type: 'success'
      			});
      			this.addproshow = false
      		}else{
      			this.$message.error(response.data.msg.info);
      		}
      	})
      },
      peizhikai2:function(){
        this.addproshow = true
      },
      peizhikai:function(who,channel_id){
        //检测初始化
        this.ischeck = false
        this.nopz = false
        this.upbm = ""
        this.addproshow = true



        // this.all2.index = who
        // this.inputadd.channel_id = channel_id
        // this.getpeizhi()
        // if(this.inputadd.channel_id){
        //   this.addproshow = true
        // }else{
        //   this.$message.error('请先选择渠道');
        // }
      },
      getpeizhi:function(){
        return new Promise((res,rej)=>{
          axios.get('/api/plan-market/upstream/product/list?channel_id='+this.inputadd.channel_id)
          	.then(response => {
          		if (response.data.msg.code == 0) {
                this.inputadd.upstream_product_name = response.data.data[0].y_name
                this.inputlistall=JSON.parse(response.data.data[0].upstream_config_type)
                //添加数据绑定
                for(var i=0;i<this.inputlistall.length;i++){
                	if(this.inputlistall[i].type=='text'){
                		this.inputadd.data[this.inputlistall[i].key]=''
                		this.inputlist.push(this.inputlistall[i])
                	}else if(this.inputlistall[i].type=='radio'){
                		this.inputadd.data[this.inputlistall[i].key]=null
                		this.radiolist.push(this.inputlistall[i])
                	}
                }
                console.log(this.inputadd)
                res('ok')
          		} else {
          			this.$message.error(response.data.msg.info);
          		}
          	})
        })
      },

      getjiekouqudao:function(){
        axios.get('/api/plan-market/upstream/channel/config/list')
        	.then(response => {
        		if (response.data.msg.code == 0) {
        			this.jiekouqudaolist = response.data.data
        		} else {
        			this.$message.error(response.data.msg.info);
        		}
        	})
      },
      chuangjian2:function(){
        this.xin = {
          id:"",
          name:"",
          sku:"",
		  copy_channel:1
        },
        this.chuangjianlog = true
      },
      chuangjian2go:function(){
        axios.post('/api/gth/products/copy', this.xin)
        	.then(response => {
        		if (response.data.msg.code == 0) {
        			this.$message.success('复制创建产品成功')
        			this.getpro()
              this.chuangjianlog = false
        		} else {
        			this.$message.error(response.data.msg.info);
        		}
        	})
      },
			numberManager() {
				// this.$router.push('/productionBasismanag/numberManagement/number')
				this.$router.push('/gongju/shanghao')
			},
			soldout(id) {
				this.$confirm('您真的要下架该产品吗?', '温馨提示', {
					confirmButtonText: '挥泪下架',
					cancelButtonText: '我再想想',
				}).then(() => {
					var that = this;
					console.log(id);
					var formData = new FormData();
					formData.append("product_id", id);
					formData.append("status", 0);
					axios.post('/api/plan-market/put/product', formData)
						.then(response => {
							if (response.data.msg.code == 0) {
								this.$message.success('下架成功')
								this.getpro()
							} else {
								if (response.data.msg.code == 50401) {
									that.$router.push({
										path: "/login"
									});
									return false
								}
								that.$message.error(response.data.msg.info);
							}
						})
				}).catch(() => {
					// this.$message({
					//   type: 'info',
					//   message: '已取消操作'
					// });
				});
			},
			gomoneyset: function(id) {
				this.$router.push({
					path: '/productionBasismanag/moneyset',
					query: {
						id: id
					}
				})
			},
			godaliang: function(id) {
				this.$router.push({
					path: '/daliangset',
					query: {
						id: id
					}
				})
			},
			//码上购相关
			//获取所有渠道
			mashanggetqudao: function() {
				var that = this
				axios.get('/api/plan-market/product/upstreams')
					.then(response => {
						if (response.data.msg.code == 0) {
							that.mashangqudao = response.data.data
						} else {
							that.$message.error(response.data.msg.info);
						}
					})
			},
			mashangchange: function() {
				this.mashangloading = true
				var that = this
				axios.get('/api/plan-market/upstream/product?product_id=' + this.id + '&upstream_account=' + this
						.mashangqudaoid)
					.then(response => {
						if (response.data.msg.code == 0) {
							that.mashang = response.data.data
							that.mashangloading = false
						} else {
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//根据id和渠道获取字段
			mashangget: function(id) {
				this.id = id
				this.mashangloading = true
				this.mashanglog = true
				var that = this
				axios.get('/api/plan-market/upstream/product?product_id=' + this.id)
					.then(response => {
						if (response.data.msg.code == 0) {
							that.mashang = response.data.data
							that.mashangqudaoid = response.data.data.upstream_account
							that.mashangloading = false
						} else {
							that.$message.error(response.data.msg.info);
						}
					})

			},
			//保存
			mashanggo: function() {
				var that = this
				var obj = {
					product_id: this.id,
					upstream_account: this.mashangqudaoid,
					upstream_product_name: this.mashang.upstream_product_name
				}
				for (var i in this.mashang.params) {
					obj[this.mashang.params[i].key] = this.mashang.params[i].value
				}
				axios.post('/api/plan-market/upstream/product', obj)
					.then(response => {
						if (response.data.msg.code == 0) {
							that.loading = true
							that.getpro()
							that.mashanglog = false
						} else {
							that.$message.error(response.data.msg.info);
						}
					})
			},
			// 修改库存
			stockgo: function() {
				var that = this
				axios.post('/api/plan-market/stock/manage', {
						stock: this.stock,
						product_id: this.chooseid
					})
					.then(response => {
						if (response.data.msg.code == 0) {
							that.getstock()
							that.getpro()
							that.fixstocklog = false
						} else {
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//获取库存
			getstock: function() {
				var that = this
				axios.get('/api/plan-market/stock/logs?product_id=' + this.chooseid)
					.then(response => {
						if (response.data.msg.code == 0) {
							that.stocklist = response.data.data.data
						} else {
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//点击修改库存
			changestock: function(id, stock) {
				this.kucunkanbukan = false
				this.chooseid = id
				this.stock = stock
				this.getstock()
				this.fixstocklog = true
			},
			//自动生产？
			is_auto: function() {
				console.log(this.all2.is_auto_produce)
				var that = this;
				if (this.all2.is_auto_produce == 1) {
					axios.get('/api/plan-market/product/auto?product_id=' + this.all2.id)
						.then(response => {
							if (response.data.msg.code == 0) {
								if (response.data.data != null) {

								} else {
									this.all2.is_auto_produce = 0
									// that.$message.error("该产品未开发自动生产模块，请联系您的客服寻求支持！");

                  that.$message.error("该产品未配置自动生产模块，请先配置自动生产！");
								}
							} else {
								that.$message.error(response.data.msg.info);
							}
						})
				}
			},
			goto: function() {
				this.$router.push({
					path: '/productionBasismanag/addBasis',
				})
			},
			//查看关联
			see: function(id, name) {
				this.$router.push({
					path: '/productionBasismanag/productionBasis',
					query: {
						id: id,
						name: name
					}
				})
			},
			//查看详情
			detail(id) {
				window.open(window.location.origin +  window.location.pathname + "#/productionBasismanag/detailproduct?id=" + id)
			},
			//跳转到修改页面
			go: function(id) {
				this.$router.push({
					path: '/productionBasismanag/fixproductionBasis',
					query: {
						id: id
					}
				})
			},
      xuanzeshengchanfangshi:function(){
        if(this.all2.is_auto_produce == 0){
          //手动  所有的东西置空
        }
        if(this.all2.is_auto_produce == 1){
          //自动  获取产品的上游根据id
          axios.get('/api/plan-market/product/up/products?id=' + this.all2.id)
          	.then(response => {
          		if (response.data.msg.code == 0) {

                if(response.data.data.length > 0 &&response.data.data[0].channel_id){

                  this.inputadd.channel_id = response.data.data[0].channel_id

                  Object.keys(JSON.parse(response.data.data[0].data)).forEach(item=>{

                    this.inputadd[item] = JSON.parse(response.data.data[0].data)[item]

                  })

                  console.log(this.inputadd)
                  // this.y_name=response.data.data[0].upstream_product_name
                  // this.inputadd.product_sku=''
                  // this.inputadd = JSON.parse(response.data.data[0].data)
                  // this.inputadd.id=response.data.data[0].id
                  // this.inputadd.product_id=response.data.data[0].product_id
                  // this.inputadd.upstream_account=response.data.data[0].upstream_account
                  // this.inputadd.upstream_product_name=response.data.data[0].upstream_product_name
                  // this.inputadd.channel_id=response.data.data[0].channel_id
                  // this.inputadd.first_province=response.data.data[0].first_province
                  // this.inputadd.first_city=response.data.data[0].first_city
                  // this.inputadd.first_order=response.data.data[0].first_order
                  // this.inputadd.channel_id = response.data.data[0].channel_id


                  // let p = this.getpeizhi()
                  // p.then(()=>{
                  //   Object.keys(this.inputadd).forEach(item=>{
                  //     console.log(item)
                  //   })
                  // })
                }


                // this.arr[0] = response.data.data[0]
                // {
                //     "id": 208,
                //     "product_id": 858,
                //     "upstream_account": "luoji-js-liantong-2l",
                //     "upstream_product_name": "343206300550",
                //     "data": "{\"ProductId\":\"\",\"num_address_type\":\"2\",\"num_province_code\":\"34\",\"num_city_code\":\"330\",\"channel\":\"07-4355-aemn-bdwz\",\"referrerCode\":\"3414247971\",\"suffix\":\"\",\"pageUrl\":\"\",\"resource_id\":\"\"}",
                //     "status": 100,
                //     "created_at": "2023-08-14 10:05:27",
                //     "updated_at": "2023-08-14 10:06:39",
                //     "shop_id": 50481,
                //     "channel_id": 625,
                //     "first_province": "",
                //     "first_city": "",
                //     "first_order": 0,
                //     "c_name": "江苏联通2l"
                // }
                // <el-dialog center  title="添加/编辑"  :visible.sync="addproshow" width="600px" @beforeClose="baocunpeizhi">
                // 	<el-form  label-width="120px">
                //       <el-form-item label="本地产品编码">
                //         <el-input style="width:250px" v-model="inputadd.product_sku" placeholder="请输入本地产品编码" size="small" ></el-input>
                // 			  <el-button @click="checkbm(inputadd.product_sku)" type="danger" round>检测</el-button>
                // 			  <div v-if="ischeck">
                //             <div v-if='nopz'>当前产品未配置</div>
                // 			  		<div v-else>已配置,上游编码为{{upbm}}</div>
                // 			  </div>
                //       </el-form-item>
                //       <el-form-item label="对应上游编码">
                //           <el-input v-model="inputadd.upstream_sku" placeholder="请输入对应上游编码" size="small" ></el-input>
                //       </el-form-item>
                // 		<el-form-item v-for="(item,index) in inputlistall" :key="index" :label="item.name">
                // 			<el-input v-if='item.type=="text"' @input="inputChange"  v-model="inputadd[item.key]" size="small" :type="item.type" ></el-input>
                // 			<el-radio-group v-if='item.type=="radio"' v-model="inputadd[item.key]">
                // 				<el-radio @change="inputChange" v-for="(item2,index2) in item.data"
                // 				:key="index2"
                // 				:label="item2.value" >{{item2.name}}</el-radio>
                // 			</el-radio-group>
                // 		</el-form-item>
                //   </el-form>
                // 	<div class="kflexcc" style="width: 100%;">
                // 		<el-button @click="baocunpeizhi" type="danger" round>保存配置</el-button>
                // 	</div>
                // </el-dialog>
                // this.arr[0] = {
                //   channel_id:this.inputadd.channel_id,
                //   data:JSON.stringify(this.inputadd),
                //   first_city:"",
                //   first_order: 0,
                //   first_province:"",
                //   id:"",
                //   product_id:this.all2.chooseid,
                //   upstream_account:this.inputadd.upstream_sku,
                //   upstream_product_name:this.y_name
                // }
                // {
                //     "ProductId": "",
                //     "num_address_type": "2",
                //     "num_province_code": "34",
                //     "num_city_code": "330",
                //     "channel": "07-4355-aemn-bdwz",
                //     "referrerCode": "3414247971",
                //     "suffix": "",
                //     "pageUrl": "",
                //     "resource_id": ""
                // }

                // this.y_name=response.data.data[0].upstream_product_name
                // this.inputadd.product_sku=''
                // this.inputadd = JSON.parse(response.data.data[0].data)
                // this.inputadd.id=response.data.data[0].id
                // this.inputadd.product_id=response.data.data[0].product_id
                // this.inputadd.upstream_account=response.data.data[0].upstream_account
                // this.inputadd.upstream_product_name=response.data.data[0].upstream_product_name
                // this.inputadd.channel_id=response.data.data[0].channel_id
                // this.inputadd.first_province=response.data.data[0].first_province
                // this.inputadd.first_city=response.data.data[0].first_city
                // this.inputadd.first_order=response.data.data[0].first_order


          		} else {
          			this.$message.error(response.data.msg.info);
          		}
          	})
        }
        // if (item.is_auto_produce == "手动生产") {
        // 	this.all2.is_auto_produce = '0'
        // }
        // if (item.is_auto_produce == "自动生产") {
        // 	this.all2.is_auto_produce = '1'
        // }
      },
			//修改生产方式
			changeis_auto_produce: function(item) {
        this.all2 = JSON.parse(JSON.stringify(item))
				this.is_auto_producelog = true
			},
			changeis_auto_producego: function() {
				this.loading = true
				var that = this;
				axios.post('/api/plan-market/product/edit', {
						is_auto_produce: this.all2.is_auto_produce,
						product_id: this.all2.id
					})
					.then(response => {
						if (response.data.msg.code == 0) {
							that.getpro()
							that.$message.success("修改成功");
							that.is_auto_producelog = false
						} else {
							that.$message.error(response.data.msg.info);
						}
					})
			},
			//翻页
			fanye: function(page) {
				this.loading = true
				this.page = page
				this.getpro()
			},
			daochu: function() {
				var url = '/api/gth/products/list/export?sku=' + this.sku + '&name=' + encodeURIComponent(this
					.title)
				location.href = url
			},
			//搜索
			search: function() {
				this.page = 1
				this.loading = true
				this.getpro()
			},
			//获取商品
			getpro: function() {

        axios.get('/api/gth/products?status=100&is_all=1')
        	.then(response => {
        		if (response.data.msg.code == 0) {
        			this.list2 = response.data.data
        		} else {
        			this.$message.error(response.data.msg.info);
        		}
        	})


				this.title = this.title.trim()
				var that = this;
				axios.get('/api/gth/products/list?status=100&order_by=0&page=' + this.page + '&page_size=' +
						this.pagesize + '&sku=' + this.sku + '&name=' + encodeURIComponent(this.title))
					.then(response => {
						if (response.data.msg.code == 0) {
							for (var i in response.data.data.data) {

                if (response.data.data.data[i].operator == 10099) {
                	response.data.data.data[i].operator = "广电"
                }
								// if (response.data.data.data[i].operator == 10086) {
								// 	response.data.data.data[i].operator = "移动"
								// }
								// if (response.data.data.data[i].operator == 10010) {
								// 	response.data.data.data[i].operator = "联通"
								// }
								// if (response.data.data.data[i].operator == 10000) {
								// 	response.data.data.data[i].operator = "电信"
								// }
							}
							that.total = response.data.data.total
							that.list = response.data.data.data
							that.loading = false
						} else {
							if (response.data.msg.code == 50401) {
								that.$router.push({
									path: "/login"
								});
								return false
							}
							that.$message.error(response.data.msg.info);
						}
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
  @import "@/assets/zuixin.scss";
	.index {
    /deep/ .el-select{width: 250px; margin-right: 20px;}
    /deep/ .el-input{width: 250px; margin-right: 20px;}
    /deep/ .el-select .el-input{width: 100%;}
    /deep/ .el-input__inner{ line-height: 36px; height: 36px; font-size: 12px; background: rgb(247, 248, 250); border: 0;}
    /deep/ .el-range-editor .el-range-input { background: #f7f8fa;}
    /deep/ .el-button{ padding: 11px 23px !important;}
    /deep/ .el-button--text{ padding: 11px 0 !important;}
    /deep/ .el-button--danger {
        color: #FFF;
        background-color: #2974FF;
        border-color: #2974FF;
    }

    /deep/ .el-input__inner:-moz-placeholder {
        color: rgb(140, 140, 140);
    }

    /deep/ .el-input__inner:-ms-input-placeholder {
        color: rgb(140, 140, 140);
    }

    /deep/ .el-input__inner::-webkit-input-placeholder {
        color: rgb(140, 140, 140);
    }
    /deep/ .td2 .el-button{ padding: 11px 0px !important;}

    /deep/ .pagination-container .el-select{width: 120px; margin-right: 20px;}
    /deep/ .pagination-container .el-input{width: 120px; margin-right: 20px;}
    /deep/ .pagination-container .el-input__inner{line-height: 28px; height: 28px;}
    /deep/ .el-pagination.is-background .btn-prev:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .btn-prev{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active{ background-color: #2974FF;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
        color: #fff;
    }
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
        color: #2974FF;
    }
    /deep/ .el-pager li{ border-radius: 14px; background: rgba(255, 255, 255, 1); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .btn-prev{ border-radius: 14px; padding: 0 10px;}
    /deep/ .btn-next{ border-radius: 14px; padding: 0 10px;}
		.see {
			color: #409EFF;
			margin: 20px 0;
			cursor: pointer;
		}

		.cpflex {
			display: flex;
			flex-wrap: wrap;

			/deep/ .el-form-item {
				margin-bottom: 0px;
			}
		}

		.kucun {
			.el-input {
				width: 200px;
			}

			.list {
				display: flex;
				text-align: center;
				border-bottom: 1px #EAEAEA solid;

				.bor1 {
					border-right: 1px #EAEAEA solid;

					i {
						color: #409EFF;
						font-size: 14px;
						margin-left: 10px;
						cursor: pointer;
					}
				}

				.th {
					background: #F9F9F9;
					line-height: 45px;
					flex: 1;
					font-size: 14px;
					box-sizing: border-box;
				}

				.td {
					line-height: 45px;
					font-size: 14px;
					flex: 1;
					box-sizing: border-box;
					color: #666;
				}

				.td2 {
					flex: 2
				}
			}
		}



				.o_ul {
					background: #F9F9F9;
					display: flex;

					.o_li {
						flex-basis: 160px;
						line-height: 45px;
						display: block;
						color: #727272;
						border-top: 3px #F9F9F9 solid;
						font-size: 14px;
						text-align: center;
					}

					.act {
						border-top: 3px #DD2727 solid;
						background: #FFFFFF;
					}
				}

				.title {
					border-bottom: 1px #EAEAEA solid;
					line-height: 45px;
					padding-left: 30px;
					font-size: 16px;
					background: #F9F9F9;
					color: #727272
				}

				.bsm {
					padding: 20px 20px 0 20px;

					/deep/ .el-input {
						width: 220px;
					}
				}

				.row2 {
					color: #FFF;
					margin-top: 20px;

					a {
						color: #FFF;
					}
				}

				.con {
					margin: 20px;

					.list {
						display: flex;
						text-align: center;
						border-bottom: 1px #EAEAEA solid;

						.bor1 {
							border-right: 1px #EAEAEA solid;

							i {
								color: #409EFF;
								font-size: 14px;
								margin-left: 10px;
								cursor: pointer;
							}
						}

						.th {
							background: #F9F9F9;
							line-height: 45px;
							flex: 1;
							font-size: 14px;
							box-sizing: border-box;
						}

						.td {
							line-height: 45px;
							font-size: 14px;
							flex: 1;
							box-sizing: border-box;
							color: #666;
						}

						.td2 {
							flex: 1.8
						}
					}
				}

				.el-pagination {
					text-align: right;
					margin-right: 20px;
					padding-bottom: 50px;
				}


	}
</style>
